package org.example.studentsystem_back.controller;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.example.studentsystem_back.common.CommonResponse;
import org.example.studentsystem_back.domain.Leaders;
import org.example.studentsystem_back.dto.PageDTO;
import org.example.studentsystem_back.service.LeadersService;
import org.example.studentsystem_back.vo.leaderMangeVo.LeaderVo;
import org.example.studentsystem_back.vo.userManageVo.PageLeaderVo;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@Valid
public class LeadersController {
    @Resource
    private LeadersService leadersService;

    @GetMapping("/leaders/{userId}")
    public CommonResponse<LeaderVo> getLeaders(@PathVariable("userId") String userid) {
        return leadersService.getLeaderOne(userid);
    }

    @PostMapping("/leaders/page")
    public CommonResponse<PageLeaderVo> getAllLeaders(@Valid @RequestBody PageDTO pageDTO) {
        return leadersService.getLeaders(pageDTO.getPage(),pageDTO.getLimit());
    }

    @PostMapping("/leaders/add")
    public CommonResponse<LeaderVo> addLeader(@Valid @RequestBody LeaderVo leaderVo) {
        return leadersService.insertLeaders(leaderVo);
    }

    @PostMapping("/leaders/update")
    public CommonResponse<Leaders> updateLeaders(@Valid @RequestBody Leaders leaders) {
        return leadersService.updateLeaders(leaders);
    }

    @PostMapping("/leader/delete")
    public CommonResponse<Leaders> deleteLeader(@Valid @RequestBody Leaders leaders) {
        return leadersService.deleteLeaders(leaders.getUserid());
    }

    @GetMapping("/leaders/current")
    public CommonResponse<LeaderVo> getCurrentLeader(HttpServletRequest httpServletRequest){
        return leadersService.getCurrentLeader(httpServletRequest);
    }
}
